package onjava.advance.ch01.sec01;

// 定义枚举
// 灌木丛{地面，爬行，悬挂}
enum Shrubbery {GROUND, CRAWLING, HANGING}

/**
 * 枚举类型的基本特性
 */
public class EnumClass {
    public static void main(String[] args) {
        // 遍历枚举
        for (Shrubbery s : Shrubbery.values()) {
            // 顺序
            System.out.println(s + " ordinal: " + s.ordinal());
            System.out.print(s.compareTo(Shrubbery.CRAWLING) + " ");
            System.out.print(s.equals(Shrubbery.CRAWLING) + " ");
            System.out.println(s == Shrubbery.CRAWLING);
            System.out.println(s.getDeclaringClass());
            System.out.println(s.name());
            System.out.println("*******************");
        }

        // 字符串 -> 枚举
        // 根据字符串名生成一个枚举值
        for (String s : "HANGING CRAWLING GROUND".split(" ")) {
            Shrubbery shrub = Enum.valueOf(Shrubbery.class, s);
            System.out.println(shrub);
        }
    }
}
